<?php
/**
 * Created by PhpStorm.
 * User: 35083
 * Date: 2019/6/26
 * Time: 17:50
 */

function RsaEncryptDataTest()
{
    import("myCal.RsaEncrypt#class", VENDOR_PATH);

    //设置公钥和私钥
    $rsa_private_key = ROOT_PATH."vendor/myCal/rsa_private_key.pem";
    $rsa_public_key = ROOT_PATH."vendor/myCal/rsa_public_key.pem";
    \RsaEncrypt::init($rsa_private_key,$rsa_public_key);

    $data=array();
    $data['name'] = 'Tom';
    $data['age']  = '20';
    $privEncrypt = \RsaEncrypt::privEncrypt(json_encode($data));
    echo '私钥加密后:'.$privEncrypt.'<br>';

    $publicDecrypt = \RsaEncrypt::publicDecrypt($privEncrypt);
    echo '公钥解密后:'.$publicDecrypt.'<br>';

    $publicEncrypt = \RsaEncrypt::publicEncrypt(json_encode($data));
    echo '公钥加密后:'.$publicEncrypt.'<br>';

    $privDecrypt =\RsaEncrypt::privDecrypt($publicEncrypt);
    echo '私钥解密后:'.$privDecrypt.'<br>';
}